package com.zhike.api.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhike.common.dto.CheckPhoneCodeDTO;
import com.zhike.common.dto.PhoneCodeDTO;
import com.zhike.common.dto.R;
import com.zhike.service.system.ISystemService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("api/zkim/sys")
@Api(tags = "短信模块")
public class SmsController {

    @Autowired
    private ISystemService systemService;

    @ApiOperation(value = "手机短信验证码", notes = "根据手机号获取六位验证码接口")
    @PostMapping("getPhoneCode")
    public R<String> getPhoneCode(@Validated @RequestBody PhoneCodeDTO dto) {
        return systemService.getPhoneCode(dto.getPhone(), dto.getModelKey());
    }

    @ApiOperation(value = "校验短信验证码是否正确")
    @PostMapping("checkPhoneCode")
    public R<Boolean> checkPhoneCode(@Validated @RequestBody CheckPhoneCodeDTO dto) {
        return R.success(systemService.checkPhoneCode(dto.getPhone(), dto.getCode()));
    }
}
